package com.healthdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.healthdata.dao.OutpatientMedicalCostMapper;
import com.healthdata.entity.OutpatientMedicalCost;
import com.healthdata.service.OutpatientMedicalCostService;
import com.healthdata.vo.OutpatientMedicalCostVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class OutpaitientMedicalCostServiceImpl implements OutpatientMedicalCostService {

    @Autowired
    private OutpatientMedicalCostMapper outpatientMedicalCostMapper;

    @Override
    public List<OutpatientMedicalCostVO> listByYear(Integer year) {
        List<OutpatientMedicalCost> entityList = outpatientMedicalCostMapper.selectList(
                new QueryWrapper<OutpatientMedicalCost>().eq("year", year)
        );
        return convertToVOList(entityList);
    }

    @Override
    public List<OutpatientMedicalCostVO> listByLevel(String level) {
        // 按等级查询数据库
        List<OutpatientMedicalCost> entityList = outpatientMedicalCostMapper.selectList(
                new QueryWrapper<OutpatientMedicalCost>().eq("level", level)
        );
        // 实体转换为VO并返回
        return convertToVOList(entityList);
    }

    // 实体列表转VO列表（通用方法）
    private List<OutpatientMedicalCostVO> convertToVOList(List<OutpatientMedicalCost> entityList) {
        List<OutpatientMedicalCostVO> voList = new ArrayList<>();
        for (OutpatientMedicalCost entity : entityList) {
            voList.add(convertToVO(entity));
        }
        return voList;
    }

    // 单个实体转VO（通用方法）
    private OutpatientMedicalCostVO convertToVO(OutpatientMedicalCost entity) {
        OutpatientMedicalCostVO vo = new OutpatientMedicalCostVO();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
}